
//
//  XXAlertView.m
//  dyss_v2
//
//  Created by LXF on 16/4/7.
//  Copyright © 2016年 First Facility. All rights reserved.
//

#import "XXAlertView.h"

#import "UIView+TYAutoLayout.h"
#import "UIView+cuttingLine.h"
#import "UIColor+customHEX.h"
#import "UIColor+HEX.h"
#import "Skin.h"


@interface TYAlertView ()
- (void)configureProperty;
- (void)addAction:(TYAlertAction *)action;
- (void)layoutContentViews;
- (void)addContentViews;

// text content View
@property (nonatomic, weak) UIView *textContentView;
@property (nonatomic, weak) UILabel *titleLable;
@property (nonatomic, weak) UILabel *messageLabel;

@property (nonatomic, weak) UIView *textFeildContentView;
@property (nonatomic, weak) NSLayoutConstraint *textFeildTopConstraint;
@property (nonatomic, strong) NSMutableArray *textFeilds;
@property (nonatomic, strong) NSMutableArray *textFeildSeparateViews;

// button content View
@property (nonatomic, weak) UIView *buttonContentView;
@property (nonatomic, weak) NSLayoutConstraint *buttonTopConstraint;
@property (nonatomic, strong) NSMutableArray<UIButton *>  *buttons;
@property (nonatomic, strong) NSMutableArray *actions;


@end

@interface XXAlertView ()

@property (nonatomic, strong) UIImageView *centerLineView;

@end

@implementation XXAlertView

-(void)addContentViews{
    [super addContentViews];
    [self.buttonContentView setCuttingLineWithType:xx_CuttingLineTop enabled:YES color:[UIColor colorWithHexString:@"#32cc9a"] insets:UIEdgeInsetsZero];
}

- (void)layoutContentViews
{
    if (!self.textContentView.translatesAutoresizingMaskIntoConstraints) {
        // layout done
        return;
    }
    if (self.alertViewWidth) {
        [self addConstarintWidth:self.alertViewWidth height:0];
    }
    
    // textContentView
    self.textContentView.translatesAutoresizingMaskIntoConstraints = NO;
    
    [self addConstarintWithView:self.textContentView topView:self leftView:self bottomView:nil rightView:self edageInset:UIEdgeInsetsMake(self.contentViewSpace, self.textLabelContentViewEdge, 0, -self.textLabelContentViewEdge)];
    
    // textFeildContentView
    self.textFeildContentView.translatesAutoresizingMaskIntoConstraints = NO;
    self.textFeildTopConstraint = [self addConstarintWithTopView:self.textContentView toBottomView:self.textFeildContentView constarint:0];
    
    [self addConstarintWithView:self.textFeildContentView topView:nil leftView:self bottomView:nil rightView:self edageInset:UIEdgeInsetsMake(0, self.textFeildContentViewEdge, 0, -self.textFeildContentViewEdge)];
    
    // buttonContentView
    self.buttonContentView.translatesAutoresizingMaskIntoConstraints = NO;
    
    self.buttonTopConstraint = [self addConstarintWithTopView:self.textFeildContentView toBottomView:self.buttonContentView constarint:0];
    
    [self addConstarintWithView:self.buttonContentView topView:nil leftView:self bottomView:self rightView:self edageInset:UIEdgeInsetsMake(0, self.buttonContentViewEdge, 0, -self.buttonContentViewEdge)];
}
//- (UIView *)createdButton{
//    
//}
- (void)addAction:(TYAlertAction *)action{
    [super addAction:action];
    [self.buttons.lastObject setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    if (self.buttons.count > 1) {
        [self.buttons.lastObject setCuttingLineWithType:xx_CuttingLineLeft enabled:YES color:[UIColor lightGrayColor] insets:UIEdgeInsetsZero];
    }
}
- (void)configureProperty
{
    [super configureProperty];
    self.backgroundColor = [UIColor whiteColor];

    self.buttonSpace = 0;
    self.buttonCornerRadius = 0;
    self.buttonContentViewEdge = 0;
    self.clipsToBounds = YES;
    self.layer.cornerRadius = 10;
}

-(UIImageView *)centerLineView{
    if (_centerLineView == nil) {
        UIImageView *a = [[UIImageView alloc] init];
        [a setImage:[UIImage skin:@"img_line_w"]];
        _centerLineView = a;
    }
    return _centerLineView;
}

@end
